package com.hongxun.modules.eys.service.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.eys.dao.EMaterialOldDao;
import com.hongxun.modules.eys.entity.EMaterialOldEntity;
import com.hongxun.modules.eys.service.EMaterialOldService;


@Service("eMaterialOldService")
public class EMaterialOldServiceImpl implements EMaterialOldService {
    @Autowired
    private EMaterialOldDao eMaterialOldDao;

    @Override
    public EMaterialOldEntity queryObject(String guid) {
        return eMaterialOldDao.queryObject(guid);
    }

    @Override
    public List<EMaterialOldEntity> queryList(Map<String, Object> map) {
        return eMaterialOldDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return eMaterialOldDao.queryTotal(map);
    }

    @Override
    public void save(EMaterialOldEntity eMaterialOld) {
        if (eMaterialOld.getGuid() == null || eMaterialOld.getGuid().equals("")) {

            eMaterialOld.setGuid(UUID.randomUUID().toString());
        }
        eMaterialOldDao.save(eMaterialOld);
    }

    @Override
    public void update(EMaterialOldEntity eMaterialOld) {
        eMaterialOldDao.update(eMaterialOld);
    }

    @Override
    public void delete(String guid) {
        eMaterialOldDao.delete(guid);
    }

    @Override
    public void deleteBatch(String[] guids) {
        eMaterialOldDao.deleteBatch(guids);
    }

    @Override
    public void insertOrReplaceOrDelete(List<EMaterialOldEntity> entities) {
        for (EMaterialOldEntity d : entities) {
            if (d.getMBDatastate().equals("删除")) {
                eMaterialOldDao.delete(d.getGuid());
            } else {
                EMaterialOldEntity eCrossCostEntity = eMaterialOldDao.queryObject(d.getGuid());
                if (eCrossCostEntity == null) {
                    eMaterialOldDao.save(d);
                } else {
                    eMaterialOldDao.update(d);
                }
            }
        }
    }

}
